package com.cci.kangdao.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cci.kangdao.dao.model.FaultCodeT;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.ServiceInformationService;
import com.cci.kangdao.utilTool.ParameterTool;

/**
 * 服务信息相关的业务
 * 
 * @author fengshuai
 *
 */
@Controller
public class ServiceInformationController {
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Autowired
	private ServiceInformationService serviceInformationService;

	/**
	 * App用户获取服务手册接口
	 */
	@RequestMapping("/getServiceHandbook.aspx")
	public ModelAndView getServiceHandbook(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.getServiceHandbook(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户搜索服务信息接口
	 */
	@RequestMapping("/searchServiceHandbook.aspx")
	public ModelAndView searchServiceHandbook(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.searchServiceHandbook(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户获取服务手册目录接口
	 */

	@RequestMapping("/getHandbookDir.aspx")
	public ModelAndView getHandbookDir(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.getHandbookDir(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户获取服务手册详细接口
	 */
	@RequestMapping("/getHandbookDetail.aspx")
	public ModelAndView getHandbookDetail(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.getHandbookDetail(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户上传手册阅读次数接口
	 */
	@RequestMapping("/uploadHandTolNum.aspx")
	public ModelAndView uploadHandTolNum(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.uploadHandTolNum(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户搜索代码故障接口(app在1.0.5版本之前的都走这个方法)
	 */
	@RequestMapping("/searchFaultCode.aspx")
	public ModelAndView searchFaultCode(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.searchFaultCode(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	
	/**
	 * App用户搜索代码故障接口(app在1.0.5版本之后的都走这个方法)
	 */
	@RequestMapping("/searchFaultCode2.aspx")
	public ModelAndView searchFaultCode2(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.searchFaultCode2(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	
	
	/**
	 * App用户查询服务首页接口
	 */
	@RequestMapping("/serviceIndex.aspx")
	public ModelAndView serviceIndex(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.serviceIndex(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	
	/**
	 * App用户症状树接口
	 */
	@RequestMapping("/faultCodeTree.aspx")
	public ModelAndView faultCodeTree(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.faultCodeTree(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户搜索代码故障接口(app在1.0.5版本之后的都走这个方法)
	 */
	@RequestMapping("/getFCCodeBySPNAndFMI.aspx")
	public ModelAndView getFCCodeBySPNAndFMI(HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceInformationService.getFCCodeBySPNAndFMI(map);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

    /**
     * App用户搜索代码故障接口(app在1.0.5版本之后的都走这个方法)
     */
    @RequestMapping("/getSMN.aspx")
    public ModelAndView getSMN(HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("request", request);
            map.put("response", response);
            return serviceInformationService.getSMN(map);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            String msg = "{\"status\":-99,\"msg\":\"未知错误\"}";
            ParameterTool.writeResponse(response, msg);
        }
        return null;
    }
}
